/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package EDT.actions;



import EDT.api.API;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;



import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;

/**
 *
 * @author ali
 */
public class GetCalendIcsAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
       String type = request.getParameter("type");
       int id = Integer.parseInt(request.getParameter("id"));
       int grpAnneeEc = Integer.parseInt(request.getParameter("GrpAnneeEc"));
       int periode = Integer.parseInt(request.getParameter("periode"));
       int nbrPeriode = Integer.parseInt(request.getParameter("nbrPriode"));
       
               
        
     response.setContentType("application/text");
     
     response.setHeader("Content-Disposition","attachment;filename="+type+grpAnneeEc+".ics");
 
     
     ArrayList<String> calend= API.getCalendrierICS(type,id,
                    grpAnneeEc,periode,nbrPeriode);
     
     for (String ligne : calend){
         response.getWriter().println(ligne);
     }
     //response.getWriter().println("helooooo");
     //response.getWriter().println("9iw");
         
   return null;
  
    }
    
   
}
